package com.joplus.housekeeper.utils;

import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;

import com.joplus.housekeeper.ui.view.RotateView;

/**
 * jo+旋转动画
 *author wutingxi
 *time 2016/9/23 11:34
 */
public class JoRotatorUtils {


    /**
     * 图片不停的右螺旋旋转
     * @param imageView
     */
    public static void RotatorRight(ImageView imageView) {
        RotateAnimation an = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        an.setInterpolator(new LinearInterpolator());
        an.setRepeatCount(-1);//重复次数
        an.setFillAfter(true);//停在最后
        an.setDuration(4000);
        //动画开始
        imageView.startAnimation(an);

    }


    public static void Rotator3D(float start, float end, ImageView imageView) {
        // 计算中心点
        final float centerX = imageView.getWidth() / 2.0f;
        final float centerY = imageView.getHeight() / 2.0f;
        // Create a new 3D rotation with the supplied parameter
        final RotateView rotation =
                new RotateView(start, end, centerX, centerY, 0f, false);
        rotation.setDuration(4000);
        rotation.setFillAfter(true);
        rotation.setInterpolator(new LinearInterpolator());
        rotation.setRepeatCount(-1);
        imageView.startAnimation(rotation);
    }
}
